#include <bits/stdc++.h>

using namespace std;

const int N=2e5+5;

int n,cnt,lt[N],rt[N],a[N],id[N],cp[N];
deque<deque<int> > v;

int main() {
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	
	rt[0]=1;
	deque<int> q;
	q.clear();
	q.push_back(0);
	v.push_back(q);

	for (int i=1;i<=n;) {
		deque<int> t;
		t.clear();
		t.push_back(i);
		while (i<n && a[i+1]==a[i])
			t.push_back(i+1),i++;
		
		v.push_back(t);
		cnt++;
		lt[cnt]=cnt-1,rt[cnt]=cnt+1;
		i++;
	}
	lt[cnt+1]=cnt;

	while (rt[0]!=cnt+1) {
		for (int i=rt[0];i!=cnt+1;i=rt[i]) {
			printf("%d ",v[i].front());
			v[i].pop_front();
		}
		for (int i=rt[0];i!=cnt+1;i=rt[i]) {
			if (i!=0 && i!=cnt+1 && v[i].empty()) {
				rt[lt[i]]=rt[i],lt[rt[i]]=lt[i];
				if (lt[i]!=0 && rt[i]!=cnt+1 && !v[lt[i]].empty() && !v[rt[i]].empty() && a[v[lt[i]].front()]==a[v[rt[i]].front()]) {
					while (!v[rt[i]].empty()) {
						v[lt[i]].push_back(v[rt[i]].front());
						v[rt[i]].pop_front();
					}
					rt[lt[rt[i]]]=rt[rt[i]],lt[rt[rt[i]]]=lt[rt[i]];
				}
			}
		}
		printf("\n");
	}
	
	return 0;
}
